package com.rwy.web.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.CharacterEncodingFilter;

@Component
public class FilterRegistration {
	@Bean
    public FilterRegistrationBean characterFilterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        CharacterEncodingFilter encoding_filter = new CharacterEncodingFilter();
        registrationBean.setFilter(encoding_filter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("encoding", "UTF-8");
        registrationBean.setName("encoding_filter");
        registrationBean.setOrder(1);
        return registrationBean;
    }
	
	@Bean
    public FilterRegistrationBean openCorsFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        SimpleCORSFilter encoding_filter = new SimpleCORSFilter();
        registrationBean.setFilter(encoding_filter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("accessDomain", "*");
        registrationBean.setName("cors");
        registrationBean.setOrder(3);
        return registrationBean;
    }
}
